package com.kgc.controller;


    /**
     * @program: logAndSign
     *
     * @description: 文件下载
     *
     * @author: Cheng
     *
     * @create: 2022-04-17 17:55
     **/
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

@Controller
@RequestMapping("/file")
@CrossOrigin
public class FileController {


    @RequestMapping("/getImg")
    public void getImg(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String img = "E://idea壁纸/"+request.getParameter("img");
        File file = new File(img);
        if (file.exists()){
            InputStream inputStream = new FileInputStream(file);
            ServletOutputStream outputStream = response.getOutputStream();
            byte[] b = new byte[1024];
            int n;
            while ((n=inputStream.read(b))!=-1){
                outputStream.write(b,0,n);
            }
            outputStream.close();
            inputStream.close();
        }
    }
}



